package biz;

import dao.ColortbDAO;
import entity.ColortbEntity;

import java.sql.SQLException;
import java.util.List;

/*
 * @Description：
 *       颜色表业务处理层
 * @Author: JiangFan
 * @Date: 2019/3/8
 * @Time：15:00
 */
public class ColorBiz {
    //实例化颜色dao
    ColortbDAO cd =new ColortbDAO ();

    /** 添加颜色
     * @param ce ce由servlet中获取
     * @return
     * @throws SQLException
     * @throws ClassNotFoundException
     */
    public int addColor(ColortbEntity ce) throws SQLException, ClassNotFoundException {
        ColortbEntity c=cd.selectColorOne (ce.getColor_name ());
        return c==null?cd.insertColor (ce):0;
    }

    /**查询所有颜色信息
     * @return 返回到List集合
     */
    public List<ColortbEntity> queryColorAll()
            throws ClassNotFoundException, SQLException, InstantiationException, IllegalAccessException {
        return cd.selectColorAll ();
    }

    /** 查询颜色是否可用
     * @param color_name
     * @return 返回true表示颜色不存在
     * @throws SQLException
     * @throws ClassNotFoundException
     */
    public boolean checkColor(String color_name) throws SQLException, ClassNotFoundException {
        return cd.selectColorOne (color_name)==null;
    }

}
